import router from '@/router'
import {post} from '@/util/request'

export default {
	namespace:'statisticsOnline',
	namespaced:true,
	state:{
		isLoading:false,
		isModalLoading:false,
		onlineNumber:{},
		onlineTime:{}
	},
	mutations:{
		changeLoading(state,v){
			state.isLoading = v;
		},
		changeModalLoading(state,v){
			state.isModalLoading = v;
		},
		changeOnlineNumber(state,data){
			state.onlineNumber = data;
		},
		changeOnlineTime(state,data){
			state.onlineTime = data;
		}
	},
	actions:{
		//在綫人數
		async loadOnlineNumber({commit}){
			commit('changeLoading',true);
			let res = await post('/stat/onlineStat/onlineNumberList');
			commit('changeOnlineNumber',res.data.data);
			commit('changeLoading',false);
		},
		//在綫时长
		async loadOnlineTime({commit},data){
			commit('changeLoading',true);
			let res = await post('/stat/onlineStat/onlineDurationList',data);
			commit('changeOnlineTime',res.data.data);
			commit('changeLoading',false);
		}
		// resetPassword({commit}, {id,loginName}){
		// 	commit('changeModalLoading',true);
		// 	return post("/auth/employee/resetPassword",{id,loginName}).then((json) => {
		// 		commit('changeModalLoading',false);
		// 		return json.data;
		// 	});
		// }
	},
	subscriptions({dispatch},router){
		//给路由加监听一旦进入module绑定的页面时dispatch初始化action
		router.afterEach((to,from)=>{
			if(to.name === this.namespace){
				dispatch('reload',{})
			}
		})
	}
}
